#include <sys/types.h>
#include <sys/wait.h>
#include "../ourhdr.h"

/****
 * 退出状态
 **/
int main(void)
{
    pid_t pid;
    int status;
    
    if((pid=fork())<0)
    {
        err_sys("fork error");
    }
    else if(pid == 0)
    {
        printf("Thread pid->%d exit\n", getpid());
        exit(7);
    }

    if(wait(&status) != pid)
    {
        err_sys("wait error");
    }
    printf("main pirnt child pid -> %d\n",pid);
    pr_exit(status);

    if((pid=fork())<0)
    {
        err_sys("fork error");
    }
    else if(pid == 0)
    {
        printf("Thread pid->%d abort\n", getpid());
        abort();
    }

    if(wait(&status) != pid)
    {
        err_sys("wait error");
    }
    printf("main pirnt child pid -> %d\n",pid);
    pr_exit(status);

    if((pid=fork())<0)
    {
        err_sys("fork error");
    }
    else if(pid == 0)
    {
        printf("Thread pid->%d execute error\n", getpid());
        status /=0;
    }

    if(wait(&status)!=pid)
    {
        err_sys("wait error");
    }
    printf("main pirnt child pid -> %d\n",pid);
    pr_exit(status);
    exit(0);
}